<template>
  <section>
    <van-sticky>
      <PageHeader title="系统通知" />
    </van-sticky>

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestData">
      <div class="flex flex-col pd10 bg-color-white mt10 ml10 mr10 round-box"
           @click="onItemTap(index)"
           v-for="(item, index) in dataList"
           :key="index">
        <div class="flex flex-row flex-left pb10 font-biger">{{item.title}}</div>
        <div class="flex flex-row flex-left pb10 pt10 font-common border-top-gray">{{item.content}}</div>
        <div class="flex flex-row flex-left pb10 pt10 font-common border-top-gray color-gray-dark">{{item.publish_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
      </div>
    </van-list>
  </section>
</template>

<script>
import PageHeader from "../../componets/PageHeader";
import {myNoticeListsUri} from "../../../common/api";

export default {
  components: {
    PageHeader
  },
  data() {
    return {
      currentPage: 1,
      lastPage: 0,
      total: 0,
      pageSize: 10,
      loading: false,
      finished: false,
      dataList: [],
    }
  },
  methods: {
    onItemTap(index) {
      const item = this.dataList[index];
      if(item.url.web.length > 0) {
        this.$router.push(item.url.web);
      }
    },
    requestData() {
      const that = this;
      this.loading = true;
      const url = myNoticeListsUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage;
      this.$http.get(url).then(response => {
        let {code, msg, data} = response.body
        if (code != 0) {
          that.toast(msg);
        } else {
          that.loading = false;
          if (that.currentPage >= data.last_page) {
            that.finished = true;
          }
          that.currentPage = that.currentPage + 1;
          for (let i = 0; i < data.data.length; i++) {
            that.dataList.push(data.data[i]);
          }
          that.total = data.total;
          that.lastPage = data.last_page;
        }
      }, response => {
        // error callback
      })
    }
  },
  mounted: function () {

  }
}
</script>

<style scoped>

</style>
